﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.MountAndBlade.View.MissionViews.Order.OrderTroopPlacer
// Assembly: TaleWorlds.MountAndBlade.View, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 61152EB8-513B-4D4A-8AC0-0D1465C6CF6C
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\Native\bin\Win64_Shipping_Client\TaleWorlds.MountAndBlade.View.dll

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using TaleWorlds.Core;
using TaleWorlds.DotNet;
using TaleWorlds.Engine;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade.Missions.Handlers;

#nullable disable
namespace TaleWorlds.MountAndBlade.View.MissionViews.Order
{
  public class OrderTroopPlacer : MissionView
  {
    private bool _suspendTroopPlacer;
    private bool _isMouseDown;
    private List<GameEntity> _orderPositionEntities;
    private List<GameEntity> _orderRotationEntities;
    private bool _formationDrawingMode;
    private Formation _mouseOverFormation;
    private Formation _clickedFormation;
    private Vec2 _lastMousePosition;
    private Vec2 _deltaMousePosition;
    private int _mouseOverDirection;
    private WorldPosition? _formationDrawingStartingPosition;
    private Vec2? _formationDrawingStartingPointOfMouse;
    private float? _formationDrawingStartingTime;
    private bool _restrictOrdersToDeploymentBoundaries;
    private OrderController PlayerOrderController;
    private Team PlayerTeam;
    private bool _initialized;
    private Timer formationDrawTimer;
    public bool IsDrawingForced;
    public bool IsDrawingFacing;
    public bool IsDrawingForming;
    private bool _wasDrawingForced;
    private bool _wasDrawingFacing;
    private bool _wasDrawingForming;
    private GameEntity widthEntityLeft;
    private GameEntity widthEntityRight;
    private bool isDrawnThisFrame;
    private bool wasDrawnPreviousFrame;
    public Action OnUnitDeployed;
    private static Material _meshMaterial;

    public bool SuspendTroopPlacer
    {
      get => this._suspendTroopPlacer;
      set
      {
        this._suspendTroopPlacer = value;
        if (value)
          this.HideOrderPositionEntities();
        else
          this._formationDrawingStartingPosition = new WorldPosition?();
        this.Reset();
      }
    }

    public override void AfterStart()
    {
      base.AfterStart();
      this._formationDrawingStartingPosition = new WorldPosition?();
      this._formationDrawingStartingPointOfMouse = new Vec2?();
      this._formationDrawingStartingTime = new float?();
      this._orderRotationEntities = new List<GameEntity>();
      this._orderPositionEntities = new List<GameEntity>();
      this.formationDrawTimer = new Timer(MBCommon.GetApplicationTime(), 0.0333333351f);
      this.widthEntityLeft = GameEntity.CreateEmpty(this.Mission.Scene);
      this.widthEntityLeft.AddComponent((GameEntityComponent) MetaMesh.GetCopy("order_arrow_a"));
      this.widthEntityLeft.SetVisibilityExcludeParents(false);
      this.widthEntityRight = GameEntity.CreateEmpty(this.Mission.Scene);
      this.widthEntityRight.AddComponent((GameEntityComponent) MetaMesh.GetCopy("order_arrow_a"));
      this.widthEntityRight.SetVisibilityExcludeParents(false);
    }

    private void InitializeInADisgustingManner()
    {
      this.PlayerTeam = this.Mission.PlayerTeam;
      this.PlayerOrderController = this.PlayerTeam.PlayerOrderController;
    }

    public override void OnMissionTick(float dt)
    {
      base.OnMissionTick(dt);
      if (this._initialized)
        return;
      MissionPeer component = GameNetwork.IsMyPeerReady ? GameNetwork.MyPeer.GetComponent<MissionPeer>() : (MissionPeer) null;
      if (this.Mission.PlayerTeam == null && (component == null || component.Team != this.Mission.AttackerTeam && component.Team != this.Mission.DefenderTeam))
        return;
      this.InitializeInADisgustingManner();
      this._initialized = true;
    }

    public void RestrictOrdersToDeploymentBoundaries(bool enabled)
    {
      this._restrictOrdersToDeploymentBoundaries = enabled;
    }

    private void UpdateFormationDrawingForFacingOrder(bool giveOrder)
    {
      this.isDrawnThisFrame = true;
      List<WorldPosition> simulationAgentFrames;
      this.PlayerOrderController.SimulateNewFacingOrder(OrderController.GetOrderLookAtDirection((IEnumerable<Formation>) this.PlayerOrderController.SelectedFormations, this.MissionScreen.GetOrderFlagPosition().AsVec2), out simulationAgentFrames);
      int entityIndex = 0;
      this.HideOrderPositionEntities();
      foreach (WorldPosition worldPosition in simulationAgentFrames)
      {
        this.AddOrderPositionEntity(entityIndex, worldPosition.GetGroundVec3(), giveOrder);
        ++entityIndex;
      }
    }

    private void UpdateFormationDrawingForDestination(bool giveOrder)
    {
      this.isDrawnThisFrame = true;
      List<WorldPosition> simulationAgentFrames;
      this.PlayerOrderController.SimulateDestinationFrames(out simulationAgentFrames);
      int entityIndex = 0;
      this.HideOrderPositionEntities();
      foreach (WorldPosition worldPosition in simulationAgentFrames)
      {
        this.AddOrderPositionEntity(entityIndex, worldPosition.GetGroundVec3(), giveOrder, 0.7f);
        ++entityIndex;
      }
    }

    private void UpdateFormationDrawingForFormingOrder(bool giveOrder)
    {
      this.isDrawnThisFrame = true;
      MatrixFrame orderFlagFrame = this.MissionScreen.GetOrderFlagFrame();
      Vec3 origin = orderFlagFrame.origin;
      Vec2 asVec2 = orderFlagFrame.rotation.f.AsVec2;
      float orderFormCustomWidth = OrderController.GetOrderFormCustomWidth((IEnumerable<Formation>) this.PlayerOrderController.SelectedFormations, origin);
      List<WorldPosition> simulationAgentFrames;
      this.PlayerOrderController.SimulateNewCustomWidthOrder(orderFormCustomWidth, out simulationAgentFrames);
      Formation formation = this.PlayerOrderController.SelectedFormations.MaxBy<Formation, int>((Func<Formation, int>) (f => f.CountOfUnits));
      int entityIndex = 0;
      this.HideOrderPositionEntities();
      foreach (WorldPosition worldPosition in simulationAgentFrames)
      {
        this.AddOrderPositionEntity(entityIndex, worldPosition.GetGroundVec3(), giveOrder);
        ++entityIndex;
      }
      float unitDiameter = formation.UnitDiameter;
      float interval = formation.Interval;
      int num1 = MathF.Max(0, (int) (((double) orderFormCustomWidth - (double) unitDiameter) / ((double) interval + (double) unitDiameter) + 9.9999997473787516E-06)) + 1;
      float num2 = (float) (num1 - 1) * (interval + unitDiameter);
      for (int index = 0; index < num1; ++index)
      {
        Vec2 a = new Vec2((float) ((double) index * ((double) interval + (double) unitDiameter) - (double) num2 / 2.0), 0.0f);
        Vec2 parentUnitF = asVec2.TransformToParentUnitF(a);
        WorldPosition worldPosition = new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, origin, false);
        worldPosition.SetVec2(worldPosition.AsVec2 + parentUnitF);
        this.AddOrderPositionEntity(entityIndex++, worldPosition.GetGroundVec3(), false);
      }
    }

    private void UpdateFormationDrawing(bool giveOrder)
    {
      this.isDrawnThisFrame = true;
      this.HideOrderPositionEntities();
      if (!this._formationDrawingStartingPosition.HasValue)
        return;
      WorldPosition formationRealEndingPosition = WorldPosition.Invalid;
      bool flag = false;
      if (this.MissionScreen.MouseVisible && this._formationDrawingStartingPointOfMouse.HasValue)
      {
        Vec2 vec2 = this._formationDrawingStartingPointOfMouse.Value - this.Input.GetMousePositionPixel();
        if ((double) MathF.Abs(vec2.x) < 10.0 && (double) MathF.Abs(vec2.y) < 10.0)
        {
          flag = true;
          formationRealEndingPosition = this._formationDrawingStartingPosition.Value;
        }
      }
      if (this.MissionScreen.MouseVisible && this._formationDrawingStartingTime.HasValue && (double) this.Mission.CurrentTime - (double) this._formationDrawingStartingTime.Value < 0.30000001192092896)
      {
        flag = true;
        formationRealEndingPosition = this._formationDrawingStartingPosition.Value;
      }
      if (!flag)
      {
        Vec3 rayBegin;
        Vec3 rayEnd;
        this.MissionScreen.ScreenPointToWorldRay(this.GetScreenPoint(), out rayBegin, out rayEnd);
        float collisionDistance;
        if (!this.Mission.Scene.RayCastForClosestEntityOrTerrain(rayBegin, rayEnd, out collisionDistance, 0.3f, BodyFlags.CommonFocusRayCastExcludeFlags | BodyFlags.BodyOwnerFlora))
          return;
        Vec3 vec3 = rayEnd - rayBegin;
        double num = (double) vec3.Normalize();
        formationRealEndingPosition = new WorldPosition(this.Mission.Scene, UIntPtr.Zero, rayBegin + vec3 * collisionDistance, false);
      }
      WorldPosition worldPosition;
      if (this._mouseOverDirection == 1)
      {
        worldPosition = formationRealEndingPosition;
        formationRealEndingPosition = this._formationDrawingStartingPosition.Value;
      }
      else
        worldPosition = this._formationDrawingStartingPosition.Value;
      if (!OrderFlag.IsPositionOnValidGround(worldPosition) || this._restrictOrdersToDeploymentBoundaries && !this.Mission.DeploymentPlan.IsPositionInsideDeploymentBoundaries(this.Mission.PlayerTeam.Side, worldPosition.AsVec2))
        return;
      bool isFormationLayoutVertical = !this.DebugInput.IsControlDown();
      this.UpdateFormationDrawingForMovementOrder(giveOrder, worldPosition, formationRealEndingPosition, isFormationLayoutVertical);
      this._deltaMousePosition *= MathF.Max((float) (1.0 - (double) (this.Input.GetMousePositionRanged() - this._lastMousePosition).Length * 10.0), 0.0f);
      this._lastMousePosition = this.Input.GetMousePositionRanged();
    }

    private void UpdateFormationDrawingForMovementOrder(
      bool giveOrder,
      WorldPosition formationRealStartingPosition,
      WorldPosition formationRealEndingPosition,
      bool isFormationLayoutVertical)
    {
      this.isDrawnThisFrame = true;
      List<WorldPosition> simulationAgentFrames;
      this.PlayerOrderController.SimulateNewOrderWithPositionAndDirection(formationRealStartingPosition, formationRealEndingPosition, out simulationAgentFrames, isFormationLayoutVertical);
      if (giveOrder)
      {
        if (!isFormationLayoutVertical)
          this.PlayerOrderController.SetOrderWithTwoPositions(OrderType.MoveToLineSegmentWithHorizontalLayout, formationRealStartingPosition, formationRealEndingPosition);
        else
          this.PlayerOrderController.SetOrderWithTwoPositions(OrderType.MoveToLineSegment, formationRealStartingPosition, formationRealEndingPosition);
      }
      int entityIndex = 0;
      foreach (WorldPosition worldPosition in simulationAgentFrames)
      {
        this.AddOrderPositionEntity(entityIndex, worldPosition.GetGroundVec3(), giveOrder);
        ++entityIndex;
      }
    }

    private void HandleMouseDown()
    {
      if (this.PlayerOrderController.SelectedFormations.IsEmpty<Formation>() || this._clickedFormation != null)
        return;
      switch (this.GetCursorState())
      {
        case OrderTroopPlacer.CursorState.Normal:
          this._formationDrawingMode = true;
          Vec3 rayBegin;
          Vec3 rayEnd;
          this.MissionScreen.ScreenPointToWorldRay(this.GetScreenPoint(), out rayBegin, out rayEnd);
          float collisionDistance;
          if (this.Mission.Scene.RayCastForClosestEntityOrTerrain(rayBegin, rayEnd, out collisionDistance, 0.3f, BodyFlags.CommonFocusRayCastExcludeFlags | BodyFlags.BodyOwnerFlora))
          {
            Vec3 vec3 = rayEnd - rayBegin;
            double num = (double) vec3.Normalize();
            this._formationDrawingStartingPosition = new WorldPosition?(new WorldPosition(this.Mission.Scene, UIntPtr.Zero, rayBegin + vec3 * collisionDistance, false));
            this._formationDrawingStartingPointOfMouse = new Vec2?(this.Input.GetMousePositionPixel());
            this._formationDrawingStartingTime = new float?(this.Mission.CurrentTime);
            break;
          }
          this._formationDrawingStartingPosition = new WorldPosition?();
          this._formationDrawingStartingPointOfMouse = new Vec2?();
          this._formationDrawingStartingTime = new float?();
          break;
        case OrderTroopPlacer.CursorState.Enemy:
        case OrderTroopPlacer.CursorState.Friend:
          this._clickedFormation = this._mouseOverFormation;
          break;
        case OrderTroopPlacer.CursorState.Rotation:
          if (this._mouseOverFormation.CountOfUnits <= 0)
            break;
          this.HideNonSelectedOrderRotationEntities(this._mouseOverFormation);
          this.PlayerOrderController.ClearSelectedFormations();
          this.PlayerOrderController.SelectFormation(this._mouseOverFormation);
          this._formationDrawingMode = true;
          WorldPosition orderWorldPosition = this._mouseOverFormation.CreateNewOrderWorldPosition(WorldPosition.WorldPositionEnforcedCache.GroundVec3);
          Vec2 direction = this._mouseOverFormation.Direction;
          direction.RotateCCW(-1.57079637f);
          this._formationDrawingStartingPosition = new WorldPosition?(orderWorldPosition);
          this._formationDrawingStartingPosition.Value.SetVec2(this._formationDrawingStartingPosition.Value.AsVec2 + direction * (this._mouseOverDirection == 1 ? 0.5f : -0.5f) * this._mouseOverFormation.Width);
          WorldPosition worldPosition = orderWorldPosition;
          worldPosition.SetVec2(worldPosition.AsVec2 + direction * (this._mouseOverDirection == 1 ? -0.5f : 0.5f) * this._mouseOverFormation.Width);
          this._deltaMousePosition = this.MissionScreen.SceneView.WorldPointToScreenPoint(worldPosition.GetGroundVec3()) - this.GetScreenPoint();
          this._lastMousePosition = this.Input.GetMousePositionRanged();
          break;
      }
    }

    private void HandleMouseUp()
    {
      if (this._clickedFormation != null)
      {
        if (this._clickedFormation.CountOfUnits > 0 && this._clickedFormation.Team == this.PlayerTeam)
        {
          Formation clickedFormation = this._clickedFormation;
          this._clickedFormation = (Formation) null;
          int cursorState = (int) this.GetCursorState();
          this._clickedFormation = clickedFormation;
          this.HideNonSelectedOrderRotationEntities(this._clickedFormation);
          this.PlayerOrderController.ClearSelectedFormations();
          this.PlayerOrderController.SelectFormation(this._clickedFormation);
        }
        this._clickedFormation = (Formation) null;
      }
      else if (this.GetCursorState() == OrderTroopPlacer.CursorState.Ground)
      {
        if (this.IsDrawingFacing || this._wasDrawingFacing)
          this.UpdateFormationDrawingForFacingOrder(true);
        else if (this.IsDrawingForming || this._wasDrawingForming)
          this.UpdateFormationDrawingForFormingOrder(true);
        else
          this.UpdateFormationDrawing(true);
        if (this.IsDeployment)
        {
          Action onUnitDeployed = this.OnUnitDeployed;
          if (onUnitDeployed != null)
            onUnitDeployed();
          UISoundsHelper.PlayUISound("event:/ui/mission/deploy");
        }
      }
      this._formationDrawingMode = false;
      this._deltaMousePosition = Vec2.Zero;
    }

    private Vec2 GetScreenPoint()
    {
      return !this.MissionScreen.MouseVisible ? new Vec2(0.5f, 0.5f) + this._deltaMousePosition : this.Input.GetMousePositionRanged() + this._deltaMousePosition;
    }

    private OrderTroopPlacer.CursorState GetCursorState()
    {
      OrderTroopPlacer.CursorState cursorState = OrderTroopPlacer.CursorState.Invisible;
      if (!this.PlayerOrderController.SelectedFormations.IsEmpty<Formation>() && this._clickedFormation == null)
      {
        Vec3 rayBegin;
        Vec3 rayEnd;
        this.MissionScreen.ScreenPointToWorldRay(this.GetScreenPoint(), out rayBegin, out rayEnd);
        float collisionDistance;
        GameEntity collidedEntity;
        if (!this.Mission.Scene.RayCastForClosestEntityOrTerrain(rayBegin, rayEnd, out collisionDistance, out collidedEntity, 0.3f, BodyFlags.CommonFocusRayCastExcludeFlags | BodyFlags.BodyOwnerFlora))
          collisionDistance = 1000f;
        if (cursorState == OrderTroopPlacer.CursorState.Invisible && (double) collisionDistance < 1000.0)
        {
          if (!this._formationDrawingMode && (NativeObject) collidedEntity == (NativeObject) null)
          {
            for (int index = 0; index < this._orderRotationEntities.Count; ++index)
            {
              GameEntity orderRotationEntity = this._orderRotationEntities[index];
              if (orderRotationEntity.IsVisibleIncludeParents() && (NativeObject) collidedEntity == (NativeObject) orderRotationEntity)
              {
                this._mouseOverFormation = this.PlayerOrderController.SelectedFormations.ElementAt<Formation>(index / 2);
                this._mouseOverDirection = 1 - (index & 1);
                cursorState = OrderTroopPlacer.CursorState.Rotation;
                break;
              }
            }
          }
          if (cursorState == OrderTroopPlacer.CursorState.Invisible && this.MissionScreen.OrderFlag.FocusedOrderableObject != null)
            cursorState = OrderTroopPlacer.CursorState.OrderableEntity;
          if (cursorState == OrderTroopPlacer.CursorState.Invisible)
            cursorState = this.IsCursorStateGroundOrNormal();
        }
      }
      if (cursorState != OrderTroopPlacer.CursorState.Ground && cursorState != OrderTroopPlacer.CursorState.Rotation)
        this._mouseOverDirection = 0;
      return cursorState;
    }

    private OrderTroopPlacer.CursorState IsCursorStateGroundOrNormal()
    {
      return !this._formationDrawingMode ? OrderTroopPlacer.CursorState.Normal : OrderTroopPlacer.CursorState.Ground;
    }

    private void AddOrderPositionEntity(
      int entityIndex,
      in Vec3 groundPosition,
      bool fadeOut,
      float alpha = -1f)
    {
      while (this._orderPositionEntities.Count <= entityIndex)
      {
        GameEntity empty = GameEntity.CreateEmpty(this.Mission.Scene);
        empty.EntityFlags |= EntityFlags.NotAffectedBySeason;
        MetaMesh copy = MetaMesh.GetCopy("order_flag_small");
        if ((NativeObject) OrderTroopPlacer._meshMaterial == (NativeObject) null)
        {
          OrderTroopPlacer._meshMaterial = copy.GetMeshAtIndex(0).GetMaterial().CreateCopy();
          OrderTroopPlacer._meshMaterial.SetAlphaBlendMode(Material.MBAlphaBlendMode.Factor);
        }
        copy.SetMaterial(OrderTroopPlacer._meshMaterial);
        empty.AddComponent((GameEntityComponent) copy);
        empty.SetVisibilityExcludeParents(false);
        this._orderPositionEntities.Add(empty);
      }
      GameEntity orderPositionEntity = this._orderPositionEntities[entityIndex];
      MatrixFrame frame = new MatrixFrame(Mat3.Identity, groundPosition);
      orderPositionEntity.SetFrame(ref frame);
      if ((double) alpha != -1.0)
      {
        orderPositionEntity.SetVisibilityExcludeParents(true);
        orderPositionEntity.SetAlpha(alpha);
      }
      else if (fadeOut)
        orderPositionEntity.FadeOut(0.3f, false);
      else
        orderPositionEntity.FadeIn();
    }

    private void HideNonSelectedOrderRotationEntities(Formation formation)
    {
      for (int index = 0; index < this._orderRotationEntities.Count; ++index)
      {
        GameEntity orderRotationEntity = this._orderRotationEntities[index];
        if ((NativeObject) orderRotationEntity == (NativeObject) null && orderRotationEntity.IsVisibleIncludeParents() && this.PlayerOrderController.SelectedFormations.ElementAt<Formation>(index / 2) != formation)
        {
          orderRotationEntity.SetVisibilityExcludeParents(false);
          orderRotationEntity.BodyFlag |= BodyFlags.Disabled;
        }
      }
    }

    private void HideOrderPositionEntities()
    {
      foreach (GameEntity orderPositionEntity in this._orderPositionEntities)
        orderPositionEntity.HideIfNotFadingOut();
      for (int index = 0; index < this._orderRotationEntities.Count; ++index)
      {
        GameEntity orderRotationEntity = this._orderRotationEntities[index];
        orderRotationEntity.SetVisibilityExcludeParents(false);
        orderRotationEntity.BodyFlag |= BodyFlags.Disabled;
      }
    }

    [Conditional("DEBUG")]
    private void DebugTick(float dt)
    {
      int num = this._initialized ? 1 : 0;
    }

    private void Reset()
    {
      this._isMouseDown = false;
      this._formationDrawingMode = false;
      this._formationDrawingStartingPosition = new WorldPosition?();
      this._formationDrawingStartingPointOfMouse = new Vec2?();
      this._formationDrawingStartingTime = new float?();
      this._mouseOverFormation = (Formation) null;
      this._clickedFormation = (Formation) null;
    }

    public override void OnMissionScreenTick(float dt)
    {
      if (!this._initialized)
        return;
      base.OnMissionScreenTick(dt);
      if (this.PlayerOrderController.SelectedFormations.Count == 0)
        return;
      this.isDrawnThisFrame = false;
      if (this.SuspendTroopPlacer)
        return;
      if (this.Input.IsKeyPressed(InputKey.LeftMouseButton) || this.Input.IsKeyPressed(InputKey.ControllerRTrigger))
      {
        this._isMouseDown = true;
        this.HandleMouseDown();
      }
      if ((this.Input.IsKeyReleased(InputKey.LeftMouseButton) || this.Input.IsKeyReleased(InputKey.ControllerRTrigger)) && this._isMouseDown)
      {
        this._isMouseDown = false;
        this.HandleMouseUp();
      }
      else if ((this.Input.IsKeyDown(InputKey.LeftMouseButton) || this.Input.IsKeyDown(InputKey.ControllerRTrigger)) && this._isMouseDown)
      {
        if (this.formationDrawTimer.Check(MBCommon.GetApplicationTime()) && !this.IsDrawingFacing && !this.IsDrawingForming && this.IsCursorStateGroundOrNormal() == OrderTroopPlacer.CursorState.Ground && this.GetCursorState() == OrderTroopPlacer.CursorState.Ground)
          this.UpdateFormationDrawing(false);
      }
      else if (this.IsDrawingForced)
      {
        this.Reset();
        this.HandleMouseDown();
        this.UpdateFormationDrawing(false);
      }
      else if (this.IsDrawingFacing || this._wasDrawingFacing)
      {
        if (this.IsDrawingFacing)
        {
          this.Reset();
          this.UpdateFormationDrawingForFacingOrder(false);
        }
      }
      else if (this.IsDrawingForming || this._wasDrawingForming)
      {
        if (this.IsDrawingForming)
        {
          this.Reset();
          this.UpdateFormationDrawingForFormingOrder(false);
        }
      }
      else if (this._wasDrawingForced)
        this.Reset();
      else
        this.UpdateFormationDrawingForDestination(false);
      foreach (GameEntity orderPositionEntity in this._orderPositionEntities)
        orderPositionEntity.SetPreviousFrameInvalid();
      foreach (GameEntity orderRotationEntity in this._orderRotationEntities)
        orderRotationEntity.SetPreviousFrameInvalid();
      this._wasDrawingForced = this.IsDrawingForced;
      this._wasDrawingFacing = this.IsDrawingFacing;
      this._wasDrawingForming = this.IsDrawingForming;
      this.wasDrawnPreviousFrame = this.isDrawnThisFrame;
    }

    private bool IsDeployment
    {
      get
      {
        return this.Mission.GetMissionBehavior<SiegeDeploymentHandler>() != null || this.Mission.GetMissionBehavior<BattleDeploymentHandler>() != null;
      }
    }

    public enum CursorState
    {
      Invisible,
      Normal,
      Ground,
      Enemy,
      Friend,
      Rotation,
      Count,
      OrderableEntity,
    }
  }
}
